package com.xuecheng.media.api;


import com.alibaba.nacos.api.utils.StringUtils;
import com.xuecheng.base.execption.XueChengPlusException;
import com.xuecheng.model.RestResponse;
import com.xuecheng.media.model.po.MediaFiles;
import com.xuecheng.media.service.impl.MediaFileServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "媒资文件管理接口",tags = "媒资文件管理接口")
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/open")
public class MediaOpenController {
    private final MediaFileServiceImpl mediaFileService;
    @ApiOperation("预览文件")
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable String mediaId){
        log.info("预览文件~~~~");
        MediaFiles mediaFiles = mediaFileService.getFileById(mediaId);
        if(mediaFiles == null || StringUtils.isEmpty(mediaFiles.getUrl())){
            XueChengPlusException.cast("视频还没有转码处理");
        }
        String concat = (mediaFiles.getUrl());
        return RestResponse.success(concat);

    }
}
